* ***************************************************************************************
* Auer, Levchenko and Saure(2018): Inflation spillovers through input linkages
* ***************************************************************************************
* Notes: 
* 		(1) If there are more than one versions of Matlab or Gauss on your PC, 
*			please enter the full path of the preferred exe file while using the "shell" command.
* 		(2) Gauss scripts might work in the second trial or might need to be run directly from Gauss.
* ***************************************************************************************
clear
set more off, permanently
* ***************************************************************************************
* ===== Folder setting
* ***************************************************************************************
di `"  Please type below the full path for the "ALS_data_and_replication_files" folder: "' _request(rootfolder)
di `"  global rootfolder = $rootfolder "'

* ***************************************************************************************
* ===== Retrieving data (~5 h 30 min)
* ***************************************************************************************
cd "$rootfolder\data"

do "Step1Concordances.do"
do "Step2PPI.do"
do "Step3WIOD.do"
do "Step4CPIservices.do"
do "Step5ULC.do"

* ***************************************************************************************
* ===== Analysis 
* ***************************************************************************************
* Part I (~6 h)
cd "$rootfolder\analysis"
* - Prepare data to generate cost shocks 
do "Step1prepare_countrySector.do"
do "Step2prepare_fx.do"
do "Step3prepare_wiod.do"
do "Step4prepare_ppi_cpi.do"

* Part II - (~30 min)
cd "$rootfolder\analysis"
* - Generate cost shocks under various scenarios
shell matlab -r "Step5generate_costShocks_17X31" -nodesktop
shell matlab -r "Step6generate_costShocks_18X31" -nodesktop
shell matlab -r "Step7generate_costShocks_35X31" -nodesktop

* Part III - (~30 min)
cd "$rootfolder\analysis"
* - OLS and static factor analyses, prepare data for dynamic factor analyses
* (Please make sure to run once the previous step has been completed)
do "Step8ols_static_factor_analysis.do"

* - Dynamic factor:
do "Step9prepare_inputs_three_factors.do"

* - one-factor
shell "C:\Program Files\gauss17\gauss.exe" -r "Step10_Otrok_one_factor_dynamic.gss" - nodesktop
shell "C:\Program Files\gauss17\gauss.exe" -r "Step11_Otrok_one_factor_dynamic_ulc.gss" - nodesktop

* Part IV (~1 day or more)
* - three-factors
shell "C:\Program Files\gauss17\gauss.exe" -r "Step12_Otrok_three_factors_dynamic_ppi.gss" -nodesktop
shell "C:\Program Files\gauss17\gauss.exe" -r "Step13_Otrok_draws_analyse_results_ppi.gss" -nodesktop

* Part V (~1 day or more)
shell "C:\Program Files\gauss17\gauss.exe" -r "Step14_Otrok_three_factors_dynamic_cost.gss" -nodesktop
shell "C:\Program Files\gauss17\gauss.exe" -r "Step15_Otrok_draws_analyse_results_cost.gss" -nodesktop

* ***************************************************************************************
* ===== Figures (~ 10 min)
* (can also be run after "analysis\Step3prepare_wiod.do")
* ***************************************************************************************
cd "$rootfolder\figures"

do "Step1_figures_1_2_3.do"
shell matlab -r "Step2_figure_4" -nodesktop

* (Please make sure to run once the previous step has been completed)
do "Step3_figure_4_6_prepare_5.do"
shell matlab -r "Step4_figure_5" -nodesktop



